$(()=>{
    let code;
    $("#sendMail").click(()=>{
        $("#first").addClass("el-loading");
        let email=$("#email").val();
        $.post("{LINK_user/basic/setpassword/sendMail}",{
            email:email
        },text=>{
            $("#first").removeClss("el-loading");
            let data=JSON.parse(text);
            if(data.status){
                code=data.code;
                dialog("提示","邮件发送成功，请检查您的邮箱。");
            }else{
                dialog("错误","邮件发送失败");
            }
        })
    });
    $("#nextBtn").click(()=>{
        $("first").addClass("el-loading");
        let email=$("#email").val();
        let code_val=$("#code").val();
        if(code_val==code){
            $.post("{LINK_user/basic/setpassword/verify}",{
                email:email
            },text=>{
                $("#first").removeClass("el-loading");
                let data=JSON.parse(text);
                if(data.status){
                    $("#first").hide();
                    $("#next").show();
                    dialog("提示","邮箱验证成功，请设置新密码");
                }else{
                    dialog("错误",data.msg);
                }
            });
        }else{
            dialog("错误","验证码不正确");
        }
    });
    $("#finish").click(()=>{
        $("#next").addClass("el-loading");
        let password=$("#password").val();
        let confirm=$("#confirm").val();
        if(password==confirm){
            if(password.length>=6&&password.length<=25){
                $.post("{LINK_user/basic/setpassword}",{
                    password:password
                },text=>{
                    $("#next").removeClass("el-loading");
                    let data=JSON.parse(text);
                    if(data.status){
                        dialog("提示","密码修改成功，请重新登录！");
                        location.href="{LINK_login}";
                    }else{
                        dialog("错误","密码修改失败："+data.msg);
                    }
                });
            }else{
                $("#next").removeClass("el-loading");
                dialog("错误","密码必须为6-25个字符");
            }
        }else{
            $("#next").removeClass("el-loading");
            dialog("错误","两次密码不一致");
        }
    });
});